package td.pt.event;

import td.domain.Thought;
import td.domain.Topic;

import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.HasHandlers;
import com.google.gwt.event.shared.HandlerRegistration;

public class EditEvent extends GwtEvent<EditEvent.EditHandler> {

	public static Type<EditHandler> TYPE = new Type<EditHandler>();

	public interface EditHandler extends EventHandler {
		void onEdit(EditEvent event);
	}

	public interface EditHasHandlers extends HasHandlers {
		HandlerRegistration addEditHandler(EditHandler handler);
	}

	private Topic topic;
	private Thought thought;

	public EditEvent() {
	}

	public EditEvent(Topic topic) {
		this.topic = topic;
	}

	public EditEvent(Thought thought) {
		this.thought = thought;
	}
	
	/**
	 * @return the topic
	 */
	public Topic getTopic() {
		return topic;
	}
	
	/**
	 * @return the thought
	 */
	public Thought getThought() {
		return thought;
	}

	@Override
	protected void dispatch(EditHandler handler) {
		handler.onEdit(this);
	}

	@Override
	public Type<EditHandler> getAssociatedType() {
		return TYPE;
	}

	public static Type<EditHandler> getType() {
		return TYPE;
	}

	public static void fire(HasHandlers source) {
		source.fireEvent(new EditEvent());
	}
}
